package com.chenwc.util.translate.google;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * 加载谷歌翻译配置文件
 * @author chenwc
 * @date 2024/8/26
 */
public class LoadGooglePropertiesFile {

    private static final File FILE = new File("1.txt");

    private static final String GOOGLE_PROPERTIES_PATH = FILE.getAbsolutePath().replace("1.txt", "") + "src/main/resources/google.properties";

    /**
     * 加载谷歌翻译配置文件
     * @return 谷歌翻译配置
     */
    public static Properties loadGooglePropertiesFile() {
        Properties props = new Properties();
        try {
            props.load(new FileInputStream(GOOGLE_PROPERTIES_PATH));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return props;
    }

    /**
     * 存储谷歌翻译配置文件
     * @param props 谷歌翻译配置
     */
    public static void storeGoogleProperties(Properties props){
        try {
            props.store(new FileOutputStream(GOOGLE_PROPERTIES_PATH), "");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
